package com.dannypatterson.videochat.services {
	
	import com.dannypatterson.as3p2p.Peer;
	
	import flash.events.EventDispatcher;
	
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	/**
	 * @author Danny Patterson
	 */
	public class RegisterUserService extends EventDispatcher implements IService {
		
		private var remoteObject:RemoteObject;
		private var peer:Peer;
		
		public function RegisterUserService(peer:Peer) {
			this.peer = peer;
			remoteObject = new RemoteObject();
			remoteObject.endpoint = "http://www.dannypatterson.com/flex2gateway";
			remoteObject.destination = "ColdFusion";
			remoteObject.source = "com.dannypatterson.stratus.StratusUserService";
			remoteObject.showBusyCursor = true;
			remoteObject.addEventListener(ResultEvent.RESULT, onResult, false, 0, true);
			remoteObject.addEventListener(FaultEvent.FAULT, onFault, false, 0, true);
		}
		
		private function onResult(event:ResultEvent):void {
			dispatchEvent(event);
		}
		
		private function onFault(event:FaultEvent):void {
			dispatchEvent(event);
		}
		
		/**
		 * @see com.dannypatterson.stratus.services.IService#execute
		 */
		public function execute():void {
			remoteObject.registerUser(peer.id, peer.name);
		}

	}
	
}